import { depositList , depositPayment} from '../../../../api/deposit'
const util = require('../../../../utils/util.js')
Page({
  data: {
    id:'',
    tranSn:'',
    depositId:'',
    name:'',
    credit:'',
    debit:'',
    PaymentAmount:'0.00'
  },
  onLoad: function(options) {
    var _this = this;
    this.setSaveParameters(JSON.parse(options.item))
  },
  priceFormat(value) {
    var toFixedNum = Number(value).toFixed(3);
    var realVal = toFixedNum.substring(0, toFixedNum.toString().length - 1);
    return realVal;
  },
  setSaveParameters(item){
    this.data.id = item.id
    this.data.name = item.name
    this.data.PaymentAmount = this.priceFormat(item.credit - item.debit)
    this.setData({
      name: this.data.name,
      PaymentAmount:this.data.PaymentAmount,
    })
  },
  logistics(data) {
    console.log(data)
    this.data.logisticsIndex = data.target.dataset.index;
    this.data.logisticsTitle = this.stars(data.target.dataset.index)
    this.setData({
      logisticsIndex: this.data.logisticsIndex,
      logisticsTitle: this.data.logisticsTitle
    })
  },
  textareaIndex(data) {
    console.log(data)
    this.data.textIndex = data.target.dataset.index
  },
  metaClick(data) {
    this.data.tranSn = data.detail.images[0]
  },
  confirmClick() {
    if( this.data.tranSn == "" ){
      wx.showToast({
        title: '请先上传付款凭证',
        icon: 'none',
        duration: 2000
      })      
      return false
    }

    let params = {}
    params.depositId = this.data.id
    params.tranSn = this.data.tranSn
    depositPayment(params).then(res=>{
      wx.showToast({
        title: "支付成功",
        icon: 'none',
        duration: 3000,
        success:function(){
          wx.navigateTo({
            url:'/pages/member/share/rechargeManagement/list',
          })
        }
      })
    }).catch(error=>{
      wx.showToast({
        title: error.content,
        icon: 'none',
        duration: 3000,
      })
    })

  }
})
